<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="法人代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankNoCd">
              <a-select
                show-search
                allow-clear
                v-model="model.bankNoCd"
                style="width: 100%"
                placeholder="请选择法人代码"
              >
                <a-select-option v-for="item in bankNoCdsOptions" :key="item.value" :value="item.value" :label="item.label">
                  {{ item.label }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="数据日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sjrq">
              <j-date placeholder="请选择数据日期" v-model="model.sjrq"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="任务开始日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="startDate">
              <j-date placeholder="请选择任务开始日期" v-model="model.startDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="任务截止日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endDate">
              <j-date placeholder="请选择任务截止日期" v-model="model.endDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <!--
          <a-col :span="12">
            <a-form-model-item label="任务状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <a-input v-model="model.status" placeholder="请输入任务状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          -->
          <!-- <a-col :span="12">
            <a-form-model-item label="报表代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reportCode">
              <a-select
                show-search
                allow-clear
                v-model="model.reportCode"
                style="width: 100%"
                placeholder="请选择报表代码"
              >
                <a-select-option v-for="item in reportsOptions" :key="item.value" :value="item.value" :label="item.label">
                  {{ item.label }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="12">
            <a-form-model-item label="主题分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="theme">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择主题分类"
                v-model="model.theme"
                dict="llbb_param_config,name,code"
                pidValue="1506488476828733442"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="12">
            <a-form-model-item label="任务批次" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskBatch">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择任务批次"
                v-model="model.taskBatch"
                dict="llbb_param_config,name,code"
                pidValue="1516616942219808769"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="12">
            <a-form-model-item label="报表类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reportType">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择报表类型"
                v-model="model.reportType"
                dict="llbb_param_config,name,code"
                pidValue="1516618015005331458"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="12">
            <a-form-model-item label="任务类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskType">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择任务类型"
                v-model="model.taskType"
                dict="llbb_param_config,name,code"
                pidValue="1516618588916142082"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="12">
            <a-form-model-item label="任务说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskDesc">
              <a-input v-model="model.taskDesc" placeholder="请输入任务说明"  ></a-input>
            </a-form-model-item>
          </a-col> -->
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'LlbbTaskCalendarForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          bankNoCd: [
            { required: true, message: '请选择法人代码!'},
          ],
          sjrq: [
            { required: true, message: '请选择数据日期!'},
          ],
          startDate: [
            { required: true, message: '请选择任务开始日期!'},
          ],
          endDate: [
            { required: true, message: '请选择任务截止日期!'},
          ],
        },
        bankNoCdsOptions:[],
        reportsOptions:[],
        url: {
          add: "/llbbTaskCalendar/llbbTaskCalendar/batchAdd",
          edit: "/llbbTaskCalendar/llbbTaskCalendar/edit",
          queryById: "/llbbTaskCalendar/llbbTaskCalendar/queryById",
          queryBankNoCdList:"/juridicalPersonManage/llbbJuridicalPerson/queryAllList",
          queryReportList:"/llbbTaskCalendar/llbbTaskCalendar/queryReportList",
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
      //初始化法人数据
      this.initBankNoCdList();
      //初始化报表数据
      this.initReportList();
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
      initBankNoCdList(){
        //获取法人数据集
        getAction(this.url.queryBankNoCdList).then((res)=>{
          if(res.success){
            this.bankNoCdsOptions = res.result.map((item, index, arr) => {
              let c = { label: item.bankname, value: item.bankNoCd, id: item.bankNoCd }
              return c
            });
          }else{
            this.$message.warning(res.message);
          }
        });
      },
      initReportList(){
        //获取报表数据集
        getAction(this.url.queryReportList).then((res)=>{
          if(res.success){
            this.reportsOptions = res.result.map((item, index, arr) => {
              let c = { label: item.REPORTTYPECODE+"-"+item.REPORTTYPENAME, value: item.REPORTTYPECODE, id: item.REPORTTYPECODE }
              return c
            });
          }else{
            this.$message.warning(res.message);
          }
        });
      },
    }
  }
</script>